package org.alexisjago.footballmanager.DAO;

import java.util.List;
import org.alexisjago.footballmanager.domain.Player;

public class PlayerJPADAO implements IPlayerDAO {

	@Override
	public Player getPlayer(int playerID) {
		Player player = PersistenceManager.entityManager.find(Player.class, playerID);
		return player;
	}

	@Override
	public void savePlayer(Player player) {
		PersistenceManager.entityManager.persist(player);
	}

	@Override
	public void updatePlayer(Player player) {
		PersistenceManager.entityManager.merge(player);
	}
	
	public List<Player> getPlayers(){
		@SuppressWarnings("unchecked")
		List<Player> players = (List<Player>)PersistenceManager.entityManager.createQuery("from Player").getResultList();
		return players;
	}
}
